package com.android.djlmapp.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.adapter.dialog.SxAdapter;
import com.android.djlmapp.listener.kaika.ShengXiaoTimeDialogListener;
import com.android.djlmapp.model.kaika.SelectTcInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 套餐生效时间弹窗
 */
public class SxTimeDialog extends Dialog {
    private Context mContext;
    private Activity mActivity;
    private List<SelectTcInfo.SpecList.Sys.Type> mList;
    private SxAdapter sxAdapter;
    private ShengXiaoTimeDialogListener listener;


    public SxTimeDialog(Context context, ArrayList<SelectTcInfo.SpecList.Sys.Type> list,
                        ShengXiaoTimeDialogListener listener) {
        super(context, R.style.BtDialogStyle);
        this.mContext = context;
        this.mActivity = (Activity) context;
        this.mList = list;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sx_time_dialog);
        //            TextView btnQd = (TextView) findViewById(R.id.tv_qd);
        TextView btnQx = findViewById(R.id.tv_qx);
        ListView lv_time = findViewById(R.id.lv_time);

        sxAdapter = new SxAdapter(mActivity, mList);
        lv_time.setAdapter(sxAdapter);

        lv_time.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);
        lv_time.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                dismiss();
                listener.TimeJump(position);
                sxAdapter.setSelectedIndex(position);
                sxAdapter.notifyDataSetChanged();
            }
        });

        btnQx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                listener.timeCancle();
                dismiss();
            }
        });

        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.CENTER;
            window.setAttributes(params);
        }
    }

}